//
//  ALSettingController.m
//  Ummy.G
//
//  Created by 安林 on 16/10/5.
//  Copyright © 2016年 安林. All rights reserved.
//

#import "ALSettingController.h"
#import "UIBarButtonItem+buttonItem.h"
#import "ALSettingCell.h"
#import "ALMyMessageController.h"
#import "ALCountSeftyController.h"
#import "ALGeneralController.h"

@interface ALSettingController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong)NSArray *titleArr;
@end

@implementation ALSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addItem];
    
    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    //取消tableView的分割线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:self.tableView];
    
    _titleArr=@[@"个人信息",@"账户与安全",@"通用"];
}
- (void)addItem{

    //------返回---------
    UIBarButtonItem *backR = [UIBarButtonItem barButtonItemWith:[UIButton buttonWithType:UIButtonTypeCustom] addTarget:self action:@selector(backRight) andImage:@"navigationButtonReturn" andHighlighted:nil];
    
    self.navigationItem.leftBarButtonItem =backR;
}



- (void)backRight{
    //没有push的时候用这个
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
}


#pragma mark 返回多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

#pragma mark 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * ID = @"setting";
    ALSettingCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [ALSettingCell loadALSettingCell];
    }
    cell.title.text = self.titleArr[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

#pragma mark 自定义cell的行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}


#pragma mark 进入“设置”界面后，点击每一个进入新的界面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row==0) { //个人信息
        ALMyMessageController *my = [[ALMyMessageController alloc]init];
        [self.navigationController pushViewController:my animated:YES];
        
    }else if (indexPath.row==1){ //账户与安全
        ALCountSeftyController *count = [[ALCountSeftyController alloc]init];
        [self.navigationController pushViewController:count animated:YES];
    }else{ //通用
        ALGeneralController *general = [[ALGeneralController alloc]init];
        [self.navigationController pushViewController:general animated:YES];
    }
}


@end
